package com.the_ring.chapter06.util;

import android.content.Context;
import android.content.SharedPreferences;

public class ShareUtil {

    private static ShareUtil util;

    private SharedPreferences preferences;

    public static ShareUtil getInstance(Context context) {
        if (util == null) {
            util = new ShareUtil(context);
        }
        return util;
    }

    public ShareUtil(Context context) {
        preferences = context.getSharedPreferences("shopping", Context.MODE_PRIVATE);
    }

    public String readString(String key, String defaultVal) {
        return preferences.getString(key, defaultVal);
    }

    public void writeString(String key, String val) {
        SharedPreferences.Editor edit = preferences.edit();
        edit.putString(key, val);
        edit.commit();
    }
}
